/// @tags: DP
#include <algorithm>
#include <cstdio>
#include <iostream>
#define rint register int

using std::cin;
using std::cout;

namespace BlueQuantum {

typedef long long LL;

constexpr int maxn = 2e3 + 3;

int f[maxn][maxn], fac[maxn], c[maxn][maxn];

inline int main() {
  int n, mod;
  cin >> n >> mod;
  fac[0] = 1;
  c[0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    c[0][i] = 1;
    for (int j = 1; j <= i; ++j) c[j][i] = (c[j - 1][i - 1] + c[j][i - 1]) % mod;
  }
  for (int i = 1; i <= n; ++i) fac[i] = (LL)fac[i - 1] * i % mod;
  f[1][1] = 1;
  for (int i = 2; i <= n; ++i)
    for (int j = 1; j <= i; ++j) f[i][j] = (LL)fac[i - 2] * j % mod * (j - 1) % mod;
  int res = 0;
  for (int i = 2; i <= n; ++i)
    for (int j = 1; j <= n - i + 1; ++j)
      res = (res + (LL)fac[j] * c[j - 1][n - i] % mod * j % mod * (n - j) % mod * f[n - j + 1][i]) %
            mod;
  cout << res;
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("P4492 [HAOI2018] 苹果树.in", "r", stdin);
  freopen("P4492 [HAOI2018] 苹果树.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
